import os
import json
config_fn = 'config.json'
default_cam_config = [[1, 'kuaijian'], [
    2, 'kuaiwei'], [3, 'caise'], [4, 'heibai']]
config = {
    "captype": "hk",
    "usbcamid": 1,
    "oktext": "12345",
    "comid": "COM3",
    "saveimg": 0,
    "onlycapimg": 0,
    "use_pic_test": 1,
    "skip": 0,
    "outsign": '05 10 00 03 00 02 04 00 04 00 0A 67 4C',
    'inds': [0, 1, 2, 3, 4],
    'cams': default_cam_config,
    'std_kuandu': 62,  # 标准像素宽度
    'liantiao_posx': [[600, 845], [2400, 2660]],
}

namemaps = {
    '变形': 'bianxin',
    '叠料': 'dieliao',
    '偏移': 'pianyi',
    '异物': 'yiwu',
    '毛丝': 'taijie',
    '溢胶': 'yijiao',
    '纵膜面废料': 'feiliao',
    '结点': 'jiedian',
    '缩胶溢胶': 'yijiaosuojiao',
    '褶皱': 'zhezhou',
    '轻膜面划伤': 'huashang',
}
namemaps = {
    '异物': 'yiwu',
}
config['quexian'] = ['yiwu']
config['namemaps'] = {}
config['namemaps_inv'] = {}
config['names'] = []
for x in namemaps:
    t = namemaps[x]
    if t in config['quexian']:
        config['namemaps_inv'][t] = x
        config['namemaps'][x] = t
        config['names'].append(x)


# suoshui 整体缩水阈值
for x in namemaps:
    t = namemaps[x]
    config[t] = [2, 60]

def config_load():
    return json.load(open(config_fn, 'r'))

def config_save():
    json.dump(config, open(config_fn, 'w'))


if not os.path.exists(config_fn):
    config_save()

config.update(config_load())
print(config)
config['quexian'] = ['yiwu']

out_img_p_kuaitou = 'D:/data/kuaitou'
out_img_p_kuaitkuaiwei = 'D:/data/kuaiwei'
out_img_p_caise = 'D:/data/caise'
out_img_p_heibai = 'D:/data/caise2'
out_img_p_caiseng = 'D:/data/NGcaise'
out_img_p_heibaing = 'D:/data/NGcaise2'
out_img_p_kuaitoung = 'D:/data/NGkuaitou'
out_img_p_kuaiweing = 'D:/data/NGkuaiwei'

config['namemaps'] = {}
config['namemaps_inv'] = {}
config['names'] = []
for x in namemaps:
    t = namemaps[x]
    if t in config['quexian']:
        config['namemaps_inv'][t] = x
        config['namemaps'][x] = t
        config['names'].append(x)